package com.zyj.test.month1.day5;

/**
 * @author Yijia Zhang
 * @create 2024-04-27 01:37
 */
public class code0011 {
    public int maxArea(int[] height) {
        int l = 0;
        int r = height.length - 1;
        int max = 0;
        while (l < r)  {
            int nowMax = (r - l) * twoMin(height[l], height[r]);
            max = twoMax(max,nowMax);
            if (height[l] <= height[r]) {
                int now = height[l];
                while (l < r && height[l] <= now) {
                    l++;
                }
            } else {
                int now = height[r];
                while (l < r && height[r] <= now) {
                    r--;
                }
            }
        }
        return max;
    }


    int twoMin(int a, int b) {
        if (a <= b) {
            return a;
        }
        return b;
    };
    int twoMax(int a, int b) {
        if (a <= b) {
            return b;
        }
        return a;
    };
}
